home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / chaos / Source / ChaosView.m < prev    next >
Text File  |  1992-02-18  |  4KB  |  186 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "ChaosView.h"
  5. #import <appkit/Application.h>
  6. #import <appkit/Slider.h>
  7. #import <appkit/Form.h>
  8. #import <math.h>
  9. #import <dpsclient/psops.h>
  10. #import <dpsclient/wraps.h>
  11. #import <stdlib.h>
  12. #import "UserPath.h"
  13.  
  14. #define    TRUE    1
  15. #define    FALSE    0
  16.  
  17. @implementation ChaosView
  18.  
  19.  
  20. static NXCoord    fixedWidth, fixedHeight;
  21.  
  22. - initFrame:(const NXRect *)frameRect
  23. {
  24.     
  25. // Initialize the View and the variables describing the boundaries
  26.  
  27.     [super initFrame:frameRect];
  28.     [self setOpaque:YES];
  29.     
  30.     userPath = newUserPath();
  31.     
  32.     fixedWidth = bounds.size.width;
  33.     fixedHeight = bounds.size.height;
  34.     
  35.     xSize = (float)fixedWidth;
  36.     ySize = (float)fixedHeight;
  37.     
  38.     printWidth = (NXCoord)480.0;
  39.     printHeight = (NXCoord)480.0;
  40.     
  41.     PRINTINVERSE = TRUE;
  42.     
  43.     return self;
  44. }
  45.  
  46. - drawSelf:(const NXRect *)rects :(int)rectCount
  47. // This is the routine where everything really happens
  48. // The background of the view is drawn and then the function itself
  49. // is calculated.  The parameters used are global to this class, so
  50. // the sliders can change them at any time.
  51. {    
  52.     int    i;
  53.  
  54.     if(rects == NULL) return self;
  55.         
  56.  
  57.     if((NXDrawingStatus != NX_DRAWING)&&(PRINTINVERSE!=FALSE)){
  58.         [self sizeTo:printWidth :printHeight];
  59.         PSsetgray(NX_WHITE);
  60.         NXRectFill(&bounds);
  61.         PSsetgray(NX_BLACK);
  62.         NXFrameRect(&bounds);
  63.     }
  64.     else{
  65.         PSsetgray(NX_BLACK);
  66.         NXRectFill(&bounds);
  67.         PSsetgray(NX_WHITE);
  68.         NXFrameRect(&bounds);
  69.     }
  70.     
  71.     beginUserPath(userPath,NO);
  72.     
  73.     UPmoveto(userPath,0,0);
  74.     
  75.     // Calculate and draw the function x(t+1)=rx(t)(1-x(t))
  76.     
  77.     for(x=0;x<=1.1;x+=stepValue){
  78.         y=x;
  79.         for(i=0;i<iterationValue;i++){
  80.             y = parameterValue*y*(1-y);
  81.         }
  82.         UPlineto(userPath,x*xSize,y*ySize);
  83.     }
  84.     
  85.     PSsetgray(NX_DKGRAY);
  86.     UPmoveto(userPath,0,0);
  87.     UPlineto(userPath,xSize,ySize);
  88.     PSsetgray(NX_WHITE);
  89.     
  90.     closePath(userPath);
  91.     
  92.     /* draw it */
  93.     endUserPath(userPath, dps_ustroke);
  94.     sendUserPath(userPath);
  95.     return self;
  96. }
  97.  
  98. - sizeTo:(NXCoord)width :(NXCoord)height
  99. // Allow resizing
  100. {
  101.     
  102.     [super sizeTo:width :height];
  103.  
  104.     [self setDrawSize    :fixedWidth
  105.                 :fixedHeight];
  106.                 
  107.     [self setDrawOrigin: (0) :(0)];
  108.     
  109.     return self;
  110. }
  111.  
  112.  
  113. // This next set of routines takes care of adjusting the parameter calues
  114. // whenever a slider is changed.  It also updates the value in the form next
  115. // to the slider.
  116.  
  117. - iterationSliderChanged:sender
  118. {
  119.     iterationValue=[sender floatValue];
  120.     [iterationFormOutlet setFloatValue:iterationValue at:0];
  121.  
  122.     [self display];
  123.     return self;
  124. }
  125.  
  126. - setIterationSliderOutlet:sender
  127. {
  128.     iterationSliderOutlet = sender;
  129.     iterationValue = [iterationSliderOutlet floatValue];
  130.     return self;
  131. }
  132.  
  133. - setIterationFormOutlet:sender
  134. {
  135.     iterationFormOutlet = sender;
  136.     [iterationFormOutlet setFloatValue:iterationValue at:0];
  137.     return self;
  138. }
  139.  
  140. - parameterSliderChanged:sender
  141. {
  142.     parameterValue=[sender doubleValue];
  143.     [parameterFormOutlet setDoubleValue:parameterValue at:0];
  144.  
  145.     [self display];
  146.     return self;
  147. }
  148.  
  149. - setParameterSliderOutlet:sender
  150. {
  151.     parameterSliderOutlet = sender;
  152.     parameterValue = [parameterSliderOutlet doubleValue];
  153.     return self;
  154. }
  155. - setParameterFormOutlet:sender
  156. {
  157.     parameterFormOutlet = sender;
  158.     [parameterFormOutlet setDoubleValue:parameterValue at:0];
  159.     return self;
  160. }
  161.  
  162. - stepSliderChanged:sender
  163. {
  164.     stepValue= [sender floatValue];
  165.     [stepFormOutlet setFloatValue:stepValue at:0];
  166.  
  167.     [self display];
  168.     return self;
  169. }
  170.  
  171. - setStepSliderOutlet:sender
  172. {
  173.     stepSliderOutlet = sender;
  174.     stepValue = [stepSliderOutlet floatValue];
  175.     return self;
  176. }
  177. - setStepFormOutlet:sender
  178. {
  179.     stepFormOutlet = sender;
  180.     [stepFormOutlet setFloatValue:stepValue at:0];
  181.     return self;
  182. }
  183.  
  184. @end
  185.  
  186.